﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
using DataAccess.Classes;

namespace Webmau.Admin
{
    public partial class DiaDiem : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                LayDanhSachDiaDiem();
        }
        private void LayDanhSachDiaDiem()
        {
            try
            {
                gvDiaDiem.DataSource = DiaDiem1.LayDanhSach();
                gvDiaDiem.DataBind();
            }
            catch
            {
            }
        }
        protected void gvDiaDiem_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                int hang = int.Parse(e.CommandArgument.ToString());
                string cot = gvDiaDiem.Rows[hang].Cells[0].Text;
                if (e.CommandName == "Delete")
                {
                    DiaDiem1.Xoa(Convert.ToInt32(cot));
                    Response.Redirect("~/Admin/DiaDiem.aspx");
                }
                if (e.CommandName == "Edit")
                    Response.Redirect("~/Admin/CapNhatDiaDiem.aspx?ID=" + cot);
            }
            catch
            {
            }
        }
        protected void btnTim_Click(object sender, EventArgs e)
        {
            try
            {
                gvDiaDiem.DataSource = DiaDiem1.TimKiem(txtTim.Text);
                gvDiaDiem.DataBind();
            }
            catch
            {
            }
        }
        protected void btnLoc_Click(object sender, EventArgs e)
        {
            try
            {
                string tinhtrang = "";
                if (cbHienThiTinhTrang.Checked == true)
                {
                    tinhtrang = "True";
                }
                if (cbHienThiTinhTrang.Checked == false)
                {
                    tinhtrang = "False";
                }
                gvDiaDiem.DataSource = DiaDiem1.LocTheoTinhTrangDuocHienThiTrangChu(Convert.ToBoolean(tinhtrang.ToString()));
                gvDiaDiem.DataBind();
            }
            catch
            {
            }

        }
        protected void btnDanhSach_Click(object sender, EventArgs e)
        {
            try
            {
                gvDiaDiem.DataSource = DiaDiem1.LayDanhSach();
                gvDiaDiem.DataBind();
            }
            catch
            {
            }
        }
        protected void gvDiaDiem_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            try
            {
                gvDiaDiem.PageIndex = e.NewPageIndex;
                LayDanhSachDiaDiem();
            }
            catch
            {
            }
        }

        protected void btnThem_Click(object sender, EventArgs e)
        {

        }
    }
}